function init () {
    $('input').daterangepicker({
        presetRanges: [
            {text: 'Last 7 days', dateStart: 'today-7days', dateEnd: 'today' },
            {text: 'Month to date', dateStart: function(){ return Date.parse('today').moveToFirstDayOfMonth();  }, dateEnd: 'today' },
            {text: 'Year to date', dateStart: function(){ var x= Date.parse('today'); x.setMonth(0); x.setDate(1); return x; }, dateEnd: 'today' },
            {text: 'The previous Month', dateStart: function(){ return Date.parse('1 month ago').moveToFirstDayOfMonth();  }, dateEnd: function(){ return Date.parse('1 month ago').moveToLastDayOfMonth();  } }
        ],
        presets: {
            allDatesAfter: 'All Dates After',
            dateRange: 'Date Range'
        },
        latestDate: Date.parse('today'),
        dateFormat: 'dd-mm-yy'
    });
} // init

function getReport () {
    var date     = Ext.fly('dateRange').getValue();
    var stockist = Ext.fly('stockistId').getValue();

    date = (date == 'Choose a Date') ? '' : date;

    var transId = Ext.Ajax.request({
        url: _webroot+'/admin/sales/weekly_bonus_report',
        method: 'POST',
        params: 'date='+date+'&stockist='+stockist,
        success: function(response, opts) {
            Ext.fly('report-list-body').update(response.responseText);
        },
        failure: function(response, opts) {
            message('server-side failure with status code '+response.status);
        },
        callback: function() {
            Ext.fly('report-list-status').ghost('b', { useDisplay:true });
        }
    });

    if (Ext.Ajax.isLoading(transId)) {
        Ext.fly('report-list-status').fadeIn().update('Loading..')
    }
} // getReport

function message (msg, focus) {
    alert(msg);

    if (typeof focus != 'undefined') {
        Ext.fly(focus).focus();
    }
} // message